/* eslint-disable indent */
'use strict'

const Controller = require('egg').Controller
const dayjs = require('dayjs')


/**
 * @controller Seat 机位图配置模块
 */

class SeatController extends Controller {

    /**
   * @summary 分页查询机位图配置列表
   * @description 分页查询机位图列表
   * @router post /v1/seat/list
   * @request body SeatList 分页参数
   * @response 0 SeatInfo
   */
    async list() {
        const { service, helper, request, validate, rule } = this.ctx
        const params = request.body

        // 参数校验
        const passed = await validate.call(this, rule.SeatList, request.body)
        if (!passed) {
            helper.error(null, '参数错误')
            return
        }

        const data = await service.seat.getSeatList(params)
        if (data) {
            helper.success(data)
        }
    }

    /**
       * @summary 新建机位图
       * @description 只有登录后才有权限
       * @router post /v1/seat/create
       * @request body SeatCreate 新增机位图
       * @response 0 SeatInfo
       */
    async create() {
        const { service, helper, request, validate, rule } = this.ctx
        const params = request.body

        // 参数校验
        const passed = await validate.call(this, rule.SeatCreate, request.body)
        if (!passed) {
            helper.error(null, '参数错误')
            return
        }
        const data = await service.seat.createSeat(params)
        if (data) {
            helper.success(data)
        }
    }

    /**
       * @summary 编辑机位图
       * @description 只有登录后才有权限
       * @router post /v1/seat/edit
       * @request body SeatEdit 参数
       * @response 0 SeatInfo
       */
    async edit() {
        const { service, helper, request, validate, rule } = this.ctx
        const params = request.body

        // 参数校验
        const passed = await validate.call(this, rule.SeatEdit, request.body)
        if (!passed) {
            helper.error(null, '参数错误')
            return
        }
        const data = await service.seat.editSeat(params)
        if (data) {
            helper.success(data)
        }
    }

    /**
       * @summary 删除机位图
       * @description 只有登录后才有权限
       * @router post /v1/seat/delete
       * @request body SeatDelete 参数
       * @response 0 SeatInfo
       */
    async delete() {
        const { service, helper, request, validate, rule } = this.ctx
        const params = request.body

        // 参数校验
        const passed = await validate.call(this, rule.SeatDelete, request.body)
        if (!passed) {
            helper.error(null, '参数错误')
            return
        }
        const data = await service.seat.deleteSeat(params)
        if (data) {
            helper.success(data)
        }
    }

    /**
       * @summary 获取指定门店机位图配置
       * @description 无需登录
       * @router post /v1/seat/get
       * @request body SeatGet 查询参数
       * @response 0 SeatInfo
       */
    async get() {
        const { service, helper, request, validate, rule } = this.ctx
        const params = request.body

        // 参数校验
        const passed = await validate.call(this, rule.SeatGet, request.body)
        if (!passed) {
            helper.error(null, '参数错误')
            return
        }
        const data = await service.seat.getSeat(params)
        if (data) {
            helper.success(data)
        }
    }
}


module.exports = SeatController
